from driver import GPIO
import service_warning

di1_irq_times = 0  # 中断计数
di1 = GPIO()
di2 = GPIO()


def init():
    """初始化adc"""
    di1.open("DI1")
    # di1.on(di1_irq_handler)


def read_adc():
    """读取adc值"""
    get_ai_current_value()
    get_ai_voltage_value()
    get_di_value()


def get_di1_value():
    value1 = di1.read()
    print("[ADC] value of di1:", value1)
    return value1


def get_di2_value():
    value2 = di2.read()
    print("[ADC] value of di2:", value2)
    return value2


def get_di_value():
    value1 = di1.read()
    value2 = di2.read()
    print("[ADC] values of di1,di2:", value1, value2)

    return value1, value2


# 按键回调中不能执行耗时操作，比如：time.sleep
def di1_irq_handler(data):
    global di1_irq_times
    di1_irq_times += 1
    print("[ADC] di1_irq_handler data:{}".format(data))
    print("[ADC] di1_irq_times:{}".format(di1_irq_times))
    service_warning.runtime_warning_service.power_off_check(data)
